package NumSort;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/***
 * bean对象用于排序
 */
public class NumSortBean implements WritableComparable<NumSortBean> {

    //定义属性
    private String NumRm;//唯一随机数
    private Long Numxh;//序号


    public NumSortBean() {
    }

    public NumSortBean(Long Numxh, String NumRm) {
        this.Numxh = Numxh;
        this.NumRm = NumRm;
    }

    //指定按照bean对象的值进行比较
    public int compareTo(NumSortBean o) {
        if (this.Numxh > o.Numxh) {
            return 1;
        } else if (this.Numxh < o.Numxh) {
            return -1;
        } else {
            //加入第二个判断条件，二次排序
            return 0;
        }
    }

    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeLong(Numxh);
        dataOutput.writeUTF(NumRm);
    }

    public void readFields(DataInput dataInput) throws IOException {
        this.Numxh = dataInput.readLong();
        this.NumRm = dataInput.readUTF();
    }

    public Long getNumxh() {
        return Numxh;
    }

    public void setNumxh(Long numxh) {
        Numxh = numxh;
    }

    public String getNumRm() {
        return NumRm;
    }

    public void setNumRm(String numRm) {
        NumRm = numRm;
    }
}